<?php

/**
 * 短信
 */
namespace Common\Api;
class SmsApi {
    
    public static $_self = null;
    
    private $_account       = 'vip_hjh';
    
    private $_pswd          = 'Tch123456';
    
    private $_url           = 'http://sapi.253.com/msg/HttpBatchSendSM';
    
    private $_needstatus    = true;
    
    private $_data          = array();
    
    public static function init() {
        return self::$_self == null ? new self() : self::$_self;
    }
    
    public function __construct() {
        $this->_data = array(
            'account' => $this->_account,
            'pswd' => $this->_pswd,
            'needstatus' => $this->_needstatus
        );
    }

    public function sendSms( $msg , $mobile ) {
        if( !$msg || !$mobile ) return false;
        $this->_data['msg'] = $msg;
        $this->_data['mobile'] = $mobile;
        return $this->_httpRequest();
    }
    
    private function _httpRequest() {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->_url . '?' . http_build_query( $this->_data ) );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $output = curl_exec($ch);
        curl_close($ch);
        $result = explode( ',' , $output );
        return $result[1] == 0 ? true : false;
    }
}

